defsym defines a recursive rewriting rule, or a recursive symbol structure for a symbol. The optional :levels is valid only for the L-system defining the rewriting levels of a rule. If is missing, then the definition is active on all levels. If there are several definition active at the same level, the L-system picks up one of them randomly when creating the output.
(initdef)
(defsym a '(a b c))
(defsym b '(c d e c b a))
(gen-trans a 4)
--> (a b c d e f g e g h i g f e f d f g h f e g ...)
(gen-notrans a 4)
--> (a a a a a b c b c d e c b a c b c d e c b c ...)
The :tree is 'tree if not given. If you want to keep multiple definitions in memory at the same time without interference problems use different trees.
(initdef 'melody1)
(defsym a '(a b) :tree 'melody1)
(defsym b '(a b) :tree 'melody1)
(gen-trans a 3 'melody1)
--> (a b c d e d d e c c d e d d e)
(initdef 'melody2)
(defsym a '(b c) :tree 'melody2)
(defsym c '(a c) :tree 'melody2)
(gen-trans a 3 'melody2)
--> (a c d c e f e d f)
Multiple Definitions
It is also possible to define two different associations for a symbol. When the output is produced the system picks randomly one of the definitions. For example,
(initdef)
(defsym a '(a b))
(defsym a '(b a))
(gen-notrans a 1)
--> (a b a)
or
--> (a a b)
Rewriting Rules
The rewriting rules are suited to modelling the growth of organic systems. In the following example the definition g is active on the levels 1 3 5 and the definition x is active on the levels 2, 4, 5 and 6. When the definitions are rewritten on the level 5, the random generator chooses one of the two values.
(initdef)
(defsym g '(g f x < + g > < - g >) :levels '(1 3 5))
(defsym x '(x < - f f f > < + f f f > f x) :levels '(2 4 5 6))
(defsym - '-)
(defsym + '+)
(defsym < '<)
(defsym > '>)
The <, >, + and - symbols have special meaning in rewriting. See gen-rewrite, transform and filter-preserve functions. The random procedure works also with gen-trans and gen-notrans functions. Other symbol defining functions are undef, which undefines rules, and initdef, which clears all definitions.